package cn.wd.service.impl;

import cn.wd.domain.BulletMsgSensitive;
import cn.wd.mapper.BulletMsgSensitiveMapper;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.service.IBulletMsgSensitiveService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BulletMsgSensitiveServiceImpl implements IBulletMsgSensitiveService {

    private final BulletMsgSensitiveMapper mapper;

    public BulletMsgSensitiveServiceImpl(BulletMsgSensitiveMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public List<BulletMsgSensitive> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public void save(BulletMsgSensitive obj) {
        mapper.insert(obj);
    }

    @Override
    public void updateById(BulletMsgSensitive obj) {
        mapper.updateByPrimaryKey(obj);
    }

    @Override
    public BulletMsgSensitive selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
        public PageResult<BulletMsgSensitive> query(QueryObject qo) {
            Long count = mapper.selectForCount(qo);
            if (count == 0) {
                return PageResult.empty(qo.getCurrentPage(),qo.getPageSize());
            }
            List<BulletMsgSensitive> list = mapper.selectForList(qo);
            return new PageResult<>(qo.getCurrentPage(),qo.getPageSize(),count,list);
        }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }
}
